/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ie.tcd.cs.railtickets.server.dao.impl;

import ie.tcd.cs.railtickets.server.dao.TravelPathDAO;
import ie.tcd.cs.railtickets.server.domain.Ticket;
import ie.tcd.cs.railtickets.server.domain.TravelPath;
import java.util.List;
import static ie.tcd.cs.railtickets.server.dao.impl.HibernateSessionFactory.getSession;

/**
 *
 * @author Wenbo Sun
 */
public class TravelPathDAOImpl extends AbstractBaseDAOImpl implements TravelPathDAO{

    public List getUniquePaths() {
        String query = "select destination.station.name from TravelPath";
        List list = getSession().createQuery(query).list();
        return list;
    }

    public List<TravelPath> findBy(String sourceStation, String destinationStation) {
        String query = "from TravelPath travelPath where travelPath.source.station.name = ? and "
                + "travelPath.destination.station.name = ?";
        List<TravelPath> result = getSession().createQuery(query).setParameter(0, sourceStation)
                .setParameter(1, destinationStation).list();
        return result;
    }

    public TravelPath findByTicket(Ticket ticket) {
        String query = "select ticket.pathTime.path from Ticket ticket where ticket = ?";
        TravelPath path = (TravelPath) getSession().createQuery(query).setParameter(0, ticket).iterate().next();
        return path;
    }


}
